package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.Station;
import com.share.device.service.IStationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 站点 controller
 */
@Tag(name = "站点接口管理")
@RestController
@RequestMapping("/station")
public class StationController extends BaseController {

    @Autowired
    private IStationService stationService;

    @Operation(summary = "分页查询站点列表")
    @GetMapping("/list")
    public TableDataInfo list(Station station){
        log.info("分页查询站点列表:{}",station);
        startPage();
        List<Station> stationList = stationService.selectStationList(station);
        return getDataTable(stationList);
    }

    //添加站点
    @Operation(summary = "新增站点")
    @PostMapping
    public AjaxResult save(@RequestBody Station station) {
        log.info("新增站点:{}",station);
        int isSuccess = stationService.saveStation(station);
        return toAjax(isSuccess);
    }

    //修改
    @Operation(summary = "修改站点")
    @PutMapping
    public AjaxResult update(@RequestBody Station station){
        log.info("修改站点:{}",station);
        int isSuccess = stationService.updateStation(station);
        return toAjax(isSuccess);
    }

    @Operation(summary = "获取站点详细信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id){
        log.info("获取站点详细信息:{}",id);
        //使用mp
        Station station = stationService.getById(id);
        return AjaxResult.success(station);
    }

    @Operation(summary = "批量删除站点")
    @DeleteMapping("/{ids}")
    public AjaxResult deleteBatch(@PathVariable List<Long> ids){
        log.info("批量删除站点:{}",ids);

        int rows = stationService.deleteBatch(ids);

        return toAjax(rows);
    }

    //启用站点对应的柜机
    @Operation(summary = "站点设置关联数据")
    @PostMapping("/setData")
    public AjaxResult setData(@RequestBody Station station)
    {
        return toAjax(stationService.setData(station));
    }

    //实现数据库站点的数据与MongoDB中的站点数据同步
    @Operation(summary = "数据库站点的数据与MongoDB中的站点数据同步")
    @GetMapping("/updateData")
    public AjaxResult updateData()
    {
        stationService.updateData();
        return success();
    }
}
